package com.example.util;

import java.util.UUID;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class TokenUtil {
    public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    /**
     * 生成token
     */
    public static String generateToken() {
        return UUID.randomUUID().toString().replace("-", "");
    }
    
    /**
     * 生成token过期时间（默认24小时）
     */
    public static String generateTokenExpireTime() {
        return LocalDateTime.now().plusHours(24).format(formatter);
    }
    
    /**
     * 检查token是否过期
     */
    public static boolean isTokenExpired(String expireTime) {
        LocalDateTime expireDateTime = LocalDateTime.parse(expireTime, formatter);
        return LocalDateTime.now().isAfter(expireDateTime);
    }
} 